﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DotNetCore.BannerManagement.Domain;
using Microsoft.Practices.Repository;

using System.Globalization;

namespace DotNetCore.BannerManagement.DAL.Domain.dnc_ClickThroughRepositoryArtifacts
{
    /// <summary>
    /// A factory object that is responsible for taking a dnc_ClickThrough
    /// and generating the corresponding SQL to insert that
    /// dnc_ClickThrough into the database. It also includes a method
    /// to grab the returned ID from the call and updating the
    /// dnc_ClickThrough object with it.
    /// </summary>
    internal class dnc_ClickThroughInsertFactory : IDbToBusinessEntityNameMapper, IInsertFactory<dnc_ClickThrough>
    {
        /// <summary>
        /// Creates the dnc_ClickThroughInsertFactory to build an insert statement for
        /// the given dnc_ClickThrough object.
        /// </summary>
        /// <param name="dnc_ClickThrough">New dnc_ClickThrough to insert into the database.</param>
        public dnc_ClickThroughInsertFactory()
        {
        }

        #region IInsertFactory<dnc_ClickThrough> Members

        public DbCommand ConstructInsertCommand(Database db, dnc_ClickThrough dnc_ClickThrough)
        {
            DbCommand command = db.GetStoredProcCommand("dbo.Insertdnc_ClickThrough");

            db.AddInParameter(command, "advertisementID", DbType.Int32, dnc_ClickThrough.AdvertisementID);
            db.AddInParameter(command, "clickThrough", DbType.DateTime, dnc_ClickThrough.ClickThrough);
            return command;
        }

        public void SetNewID(Database db, DbCommand command, dnc_ClickThrough dnc_ClickThrough)
        {
            //TODO: Provide set mapping
        }

        #endregion

        #region IDbToBusinessEntityNameMapper Members
        /// <summary>
        /// Maps a field name in the database (usually a parameter name for a stored proc)
        /// to the corresponding business entity property name.
        /// </summary>
        /// <remarks>This method is intended for error message handling, not for reflection.</remarks>
        /// <param name="dbParameter">Name of field/parameter that the database knows about.</param>
        /// <returns>Corresponding business entity field name.</returns>
        public string MapDbParameterToBusinessEntityProperty(string dbParameter)
        {
            switch (dbParameter)
            {
                case "advertisementID":
                    return "AdvertisementID";
                case "clickThrough":
                    return "ClickThrough";
                default:
                    throw new Exception(dbParameter);
            }
        }
        #endregion
    }

}

